﻿@model SuperDumpService.ViewModels.ReportViewModel

<div class="panel panel-primary">
	<div class="panel-heading">
		<h4 class="panel-title">
			<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#system-info">
				<span class="fa fa-plus"></span> System Information
			</a>
		</h4>
	</div>
	<div id="system-info" class="panel-collapse in">
		<div class="panel-body">
			@if (Model.Result.SystemContext == null) {
				<span>SystemContext is null</span>
			} else {
			<dl class="row courier-small compact">
				@if (Model.Result.SystemContext is SuperDump.Models.SDCDSystemContext) {
					// Linux Core Dump
					<dt class="col-sm-3 text-right">Platform</dt>
					<dd class="col-sm-9">@(((SuperDump.Models.SDCDSystemContext)Model.Result.SystemContext).SystemArchitecture)</dd>

					<dt class="col-sm-3 text-right">User ID</dt>
					<dd class="col-sm-9">@(((SuperDump.Models.SDCDSystemContext)Model.Result.SystemContext).Uid)</dd>

					<dt class="col-sm-3 text-right">Group ID</dt>
					<dd class="col-sm-9">@(((SuperDump.Models.SDCDSystemContext)Model.Result.SystemContext).Gid)</dd>

					<dt class="col-sm-3 text-right">Entry Point</dt>
					<dd class="col-sm-9">@String.Format("0x{0:x}", ((SuperDump.Models.SDCDSystemContext)Model.Result.SystemContext).EntryPoint)</dd>

					<dt class="col-sm-3 text-right">Page Size</dt>
					<dd class="col-sm-9">@(((SuperDump.Models.SDCDSystemContext)Model.Result.SystemContext).PageSize) bytes</dd>
				} else {
					// Windows Crash Dump
					<dt class="col-sm-3 text-right">OS version:</dt>
					<dd class="col-sm-9">@Model.Result.SystemContext.OSVersion</dd>

					<dt class="col-sm-3 text-right">Architecture:</dt>
					<dd class="col-sm-9">@Model.Result.SystemContext.ProcessArchitecture</dd>

					<dt class="col-sm-3 text-right">Process up-time:</dt>
					<dd class="col-sm-9">@Model.Result.SystemContext.ProcessUpTime</dd>

					<dt class="col-sm-3 text-right">System up-time:</dt>
					<dd class="col-sm-9">@Model.Result.SystemContext.SystemUpTime</dd>

					<dt class="col-sm-3 text-right"># of logical processors:</dt>
					<dd class="col-sm-9">@Model.Result.SystemContext.NumberOfProcessors</dd>
				}
				@if (Model.Result.SystemContext.ClrVersions != null) {
					@foreach (var clr in Model.Result.SystemContext.ClrVersions) {
						<dt class="col-sm-3 text-right">.NET CLR:</dt>
						<dd class="col-sm-9">@clr.Version (@clr.ClrFlavor)</dd>
					}
				}
			</dl>
			<dl class="row courier-small compact">
				<dt class="col-sm-3 text-right"># of modules:</dt>
				<dd class="col-sm-9">@Model.Result.SystemContext.DistinctModules().Count()</dd>
				@{
					var moduleTags = Model.Result.SystemContext.DistinctModules().SelectMany(x => x.Tags).Distinct();
					@foreach (var moduleTag in moduleTags.OrderByDescending(x => x.Importance)) {
						<dt class="col-sm-3 text-right"><span class="tag tag-@moduleTag">@moduleTag</span>-modules:</dt>
						var matchingModules = Model.Result.SystemContext.DistinctModules().Where(x => x.Tags.Contains(moduleTag));
						<dd class="col-sm-9">@matchingModules.Select(x => $"{x.FileName} ({x.Version})").Aggregate((i, j) => i + ", " + j)</dd>
					}
				}
			</dl>
			@if (Model.Result.ThreadInformation != null) {
			<dl class="row courier-small compact">

				<dt class="col-sm-3 text-right"># of threads:</dt>
				<dd class="col-sm-9">@Model.Result.ThreadInformation.Count</dd>

				@foreach (var moduleTag in Model.Result.ThreadInformation.Values.SelectMany(x => x.Tags).Distinct().OrderByDescending(x => x.Importance)) {
					<dt class="col-sm-3 text-right"><span class="tag tag-@moduleTag">@moduleTag</span>-threads:</dt>
					<dd class="col-sm-9">
						@{
							var threads = Model.Result.ThreadInformation.Values.Where(x => x.Tags.Contains(moduleTag));
							<span>
								@threads.Count()
								[@foreach (var t in threads) {
									<a href="#@t.OsId">#@t.EngineId</a>
								}]
							</span>
						}
					</dd>
				}
			</dl>
			}
			}
		</div>
	</div>
</div>